let feedComponent = {
    template: `
        <div class="feed page">
            <div class="head">
                 <div class="left" @click="back">
                    <span class="iconfont icon-ali-fanhui"></span>
                </div>
                <div class="title">{{title}}</div>
                <div class="right"></div>
            </div>
             <el-tabs v-model="state" :stretch="true" >
                <el-tab-pane label="draft" name="0"></el-tab-pane>
                <el-tab-pane label="release" name="1"></el-tab-pane>
                <el-tab-pane label="formal" name="2"></el-tab-pane>
             </el-tabs>
            <div class="main">
               <div class="content">
                   <div class="item" v-for="item in filterList" @click="handleView(item)">
                        <div class="item-name">{{item.name}}</div>
                        <div class="publisher">{{item.description}}</div>
                        <div class="state">
                            {{item.state===0?'draft':''}}
                            {{item.state===1?'release':''}}
                            {{item.state===2?'formal':''}}
                        </div>
                        <div class="controls">
                           
                            <div class="btn" v-if="title==='library'" @click.stop="handleEdit(item)" v-show="item.state===0">Update</div>   
                        </div>
            
                    </div>
               </div>

          
            </div>
        </div>
    `,
    data() {
        return {
            categoryList:[],
            filter:{
                name:null,
                description:null
            },
            title:null,
            state:0
        }

    },
    computed: {
        filterList(){
            return this.categoryList.filter((item)=>{
                return item.state == this.state
            })
        }
    },
    watch: {},
    mounted() {
        this.title = this.$route.name
        // if(this.$route.name === 'library') {
            this.fetchDataList()
        // }

    },
    activated() {

    },
    methods: {
        back(){
            this.$router.back()
        },
        handleDelete(){

        },
        handleEdit(item){
            this.$router.push({
                name: 'sections',
                query:{
                    sessionId: item.id
                }
            })
        },
        fetchDataList(){
            let filter = {
                state:{"op":"IN","value":[0,1,2]}
            }
            if(this.filter.name){
                filter.name = {
                    op:'LIKE',
                    value: '%' + this.filter.name + '%'
                }
            }
            if(this.filter.description){
                filter.description = {
                    op:'LIKE',
                    value: '%' + this.filter.description + '%'
                }
            }
            treatmentSession.getList(JSON.stringify(filter)).then((entities)=>{

                entities.sort(function(a,b){return b.id-a.id})

                this.categoryList = entities
            })
        },
        update(state,item){
            treatmentSession.update({
                id: item.id,
                state
            }).then(()=>{
                item.state = state
            })
        },
        handleView(item){
            if(this.title === 'library'){
                this.$router.push({
                    name:'detail',
                    query:{
                        sessionId: item.id
                    }
                })
            } else {
                this.$router.push({
                    name: 'result',
                    query:{
                        sessionId: item.id
                    }
                })
            }

        }
    },
    components: {},
    beforeRouteLeave(to, from, next) {

        next();
    }
}

